import { RouteRecordRaw } from "vue-router";

const ctx = require.context("@/views/", true, /\.vue/);

const routesPath: RouteRecordRaw[] = [];

ctx.keys().forEach((filePath) => {
  let path = filePath.replace(/\.\//g, "/").replace(/\/index.vue|.vue/g, "");
  console.log(ctx(filePath).default || ctx(filePath))
  if (path.includes("_")) {
    path = path.replace(/_/g, ":");
  }
  const name = path
    .replace(/:/g, "")
    .replace(/\//, "")
    .replace(/\/\w/g, ($1) => $1.slice(1).toUpperCase());
    const componentPath = filePath.replace(/\./, "");
    routesPath.push({
        path,
        name,
        component: () =>
        import(/* webpackChunkName: "`${name}`" */ `../views${componentPath}`),
    });
});

export default routesPath;
